| Class | WinkelController |
| In: |
app/controllers/winkel_controller.rb
|
| Parent: | ApplicationController |
# File app/controllers/winkel_controller.rb, line 35
35: def aankoop_stap1
36: @kar = ophalen_kar
37: if @kar.items.empty?
38: redirect_to_index('Uw winkelkar is leeg')
39: else
40: @klant = Klant.new
41: end
42: end
# File app/controllers/winkel_controller.rb, line 44
44: def aankoop_stap2
45: @kar = ophalen_kar # nodig opdat het layoutscherm de winkelkar kan tonen
46: @order = Order.new
47: end
# File app/controllers/winkel_controller.rb, line 49
49: def bewaar_klant
50: @kar = ophalen_kar # nodig opdat het layoutscherm de winkelkar kan tonen
51: @klant= Klant.new(params[:klant]) # hier gebeurt de validatie
52: if @klant.save
53: flash[:melding] = 'Uw gegevens zijn bewaard.'
54: session[:klant] = @klant # stockeer klant in session, id is nodig in order
55: redirect_to :action => :aankoop_stap2
56: else
57: render :action => :aankoop_stap1
58: end
59: end
# File app/controllers/winkel_controller.rb, line 61
61: def bewaar_order
62: @kar = ophalen_kar
63: @order = Order.new(params[:order])
64: @order.klant = session[:klant] # hier wordt klant_id door belongs_to ingevuld
65: @order.toevoegen_orderlijnen_vanuit_kar(@kar)
66: if @order.save
67: session[:klant] = session[:kar] = nil # opkuis session
68: redirect_to_index("ITMedia dankt u voor uw bestelling!")
69: else
70: render :action => :aankoop_stap2
71: end
72: end
# File app/controllers/winkel_controller.rb, line 5
5: def index
6: @products = Product.find_producten_voor_verkoop
7: @kar = ophalen_kar
8: #@page_title = '*** ITMEDIA! ***'
9: #@huidige_tijd = Time.now.strftime('%d/%m/%Y %H:%M:%S')
10: end
# File app/controllers/winkel_controller.rb, line 30
30: def leegmaken_kar
31: session[:kar] = nil
32: redirect_to_index('Uw winkelkar is leeg')
33: end
# File app/controllers/winkel_controller.rb, line 12
12: def toevoegen_aan_kar
13: begin
14: product = Product.find(params[:id])
15: rescue ActiveRecord::RecordNotFound
16: error = "U probeert een niet bestaand product #{params[:id]} op te halen"
17: logger.error(error)
18: redirect_to_index(error)
19: else
20: @kar = ophalen_kar
21: @kar.voeg_product_toe(product)
22: if request.xhr?
23: respond_to { |format| format.js }
24: else
25: redirect_to :action => :index
26: end
27: end
28: end